package com.upcode.weighing.vo.req.pc;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper=false)
public class EquipmentPostListReqVo {

    /**
     * 选中的ID
     */
    private List<String> ids;
    /**
     * 车牌号
     */
    private String vehicleId;

    /**
     * 订单开始时间
     */
    private String orderStartTime;

    /**
     * 订单结束时间
     */
    private String orderEndTime;

    /**
     * 邮寄状态 1-待邮寄 2-已邮寄
     */
    private Integer expressStatus;

    /**
     * 邮寄单号
     */
    private String wayBillNo;

    /**
     * 订单类型
     * 1-新办
     * 2-换签
     * 3-换卡
     * 4-换卡签全套
     * 5-重激活
     * 6-补签
     * 7-补卡
     * 8-补卡签全套
     */
    private Integer orderType;

    /**
     * 订单来源
     */
    private Integer orderSrc;

    /**
     * 收货地址(省)
     */
    private String receiveAddrProv;
    /**
     * 收货地址(市)
     */
    private String receiveAddrCity;
    /**
     * 收货地址(区)
     */
    private String receiveAddrCounty;


    /**
     * 收货人电话
     */
    private String receivePhone;

    /**
     * 邮寄开始时间
     */
    private String postStartTime;

    /**
     * 邮寄结束时间
     */
    private String postEndTime;

    public String checkParams(){
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        if(StringUtils.isNotBlank(orderStartTime) && StringUtils.isBlank(orderEndTime)){
            LocalDate nowDate = LocalDate.now();
            orderEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(orderStartTime) && StringUtils.isNotBlank(orderEndTime)){
            LocalDate startDate = LocalDate.parse(orderStartTime, dtf);
            LocalDate endDate = LocalDate.parse(orderEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "订单结束日期不能大于订单开始日期";
            }
            orderStartTime += " 00:00:00";
            orderEndTime += " 23:59:59";
        }

        if(StringUtils.isNotBlank(postStartTime) && StringUtils.isBlank(postEndTime)){
            LocalDate nowDate = LocalDate.now();
            postEndTime = nowDate.format(dtf);
        }
        if(StringUtils.isNotBlank(postStartTime) && StringUtils.isNotBlank(postEndTime)){
            LocalDate startDate = LocalDate.parse(postStartTime, dtf);
            LocalDate endDate = LocalDate.parse(postEndTime, dtf);
            if(endDate.isBefore(startDate)){
                return "邮寄结束日期不能大于邮寄开始日期";
            }
            postStartTime += " 00:00:00";
            postEndTime += " 23:59:59";
        }
        return null;
    }
}
